package com.itheima.service.report;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.dao.report.ReportFormDao;
import com.itheima.factory.MapperFactory;
import com.itheima.utils.TransactionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

public class ReportFormServiceImpl implements  ReportFormService{
    @Override
    public List<Map> memberReport(Integer year) {
        List<Map> map = null;
        SqlSession sqlSession = null;
        try {
            sqlSession = MapperFactory.getSqlSession();
            ReportFormDao mapper = sqlSession.getMapper(ReportFormDao.class);
            map = mapper.memberReport(year);
            String json = new ObjectMapper().writeValueAsString(map);
//            System.out.println(json);
            TransactionUtil.commit(sqlSession);
        } catch (Exception e) {
            TransactionUtil.rollback(sqlSession);
            e.printStackTrace();
        } finally {
            TransactionUtil.close(sqlSession);
        }
        return map;
    }

    public static void main(String[] args) {
        List<Map> maps = new ReportFormServiceImpl().memberReport(2020);
//        System.out.println(maps);
    }
}
